$(document).ready(function() {
	
	$("#startGameButton").click(function () {
		startGame();
	});
	
	$("#endGameButton").click(function () {
		if ( confirm('Oled Sa kindel, et soovid mängu lõpetada?')) {
			endGame();
		}	
	});
	
});

var game;
var betMultiplier;
var names = ["Batman","Alfred","Joker","Robin","Mr. Freeze","Riddler","Egghead","Penguin","Falce-Face"];
var cardValues = [14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
var timesRaised = 0;
var betLimit = 2;
var winnerDeclared = false;
var viewLog = true;
var communityCardIndex = 0;

const actionRaise = 'Raise';
const actionCheck = 'Check';
const actionCall = 'Call';
const actionFold = 'Fold';
const actionSmallBlind = 'SB';
const actionBigBlind = 'BB';

function player() {
	this.id;
	this.name;
	this.action = '';
	this.cards = new Array();
	this.money = 100;
	this.inGame = true;
	this.strongestHand = 0;
	this.betSize = 0;
	this.isHuman = false;
	this.hasActed = false;
}

function playerList() {
	var players = new Array();
	for ( var i = 0; i<names.length; i++ ) {	
	    var bot = new player();
	    bot.id = i;
	    bot.name = names[i];
	    players.push(bot); 
	}
	return players;
}

function Card( number, suit ) {
	this.number = number;
	this.suit = suit;
}

function makeDeck() {
    var values = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];
    var suits = ["S","H","D","C"];
	var deck = new Array();
    for (i=0; i<suits.length; i++) {
        for (j=0; j<values.length; j++) {
            card = new Card( values[j],suits[i] );
            deck.push(card);
        }
    }
    return deck;
}

function randOrd() {
	return (Math.round(Math.random())-0.5); 
}

function shuffleDeck(deck) {

	var numbersArray = new Array();
	var shuffledDeck = new Array();
  
	for (i=0; i < 52; i++ ) {
		numbersArray.push(i);
	}
  
	numbersArray.sort( randOrd );
 
	for ( var i = 0; i < numbersArray.length; i++) {
		shuffledDeck.push(deck[numbersArray[i]]);
	}
	return shuffledDeck;
}

function gameStatus() {
	this.players = playerList();
	this.deck = new Array();
	this.communityCards = new Array();
	this.foldPile = new Array();
	this.dealer = 0;
	this.activePlayer = this.dealer + 2;
	this.maxBet = 0;
	this.smallBlind = 2;
	this.pot = 0;
	this.playersInGame;
}

function startGame(){
	if ( confirm('Oled Sa kindel, et soovid mängu alustada?')) {
		$('#startGameButton').hide();
		$('.main').show();
		$('.playerActionButton').hide();	
		//$('#endGameButton').fadeIn(700);
		//$('#startGameButton').fadeOut(700);
		//$('.playerActionButton').fadeIn(700);
		//$('.pot').fadeIn(700);
		//$('#deck').fadeIn(700);
		game = new gameStatus();
		game.players[0].isHuman = true;
		stage = 0;
		round();
	}
}

function endGame()  {
		$('.main').fadeOut(700);
		setTimeout("location.reload(true);",800);
}

function round(){
	if ( winnerDeclared ) return;
	switch( stage ){
	case 0:
		game.deck = makeDeck();
		game.deck = shuffleDeck(game.deck);
		dealCards(game.players, game.deck);
		showPlayerCards( game.players[0] );
		isDealer( game.players[game.dealer] );
		game.playersInGame = game.players.length;
		blinds();
		betMultiplier = 1;
		
		for ( var i=0; i<game.players.length; i++ ) {
			writePlayerDataToHtml( game.players[i] );
		}
		
		playerAction();
		break;
	case 1:
		logger("Flop is on the table now");
		burn();
		playStage();
		break;
	case 2:
		logger("Turn is on the table now");
		betMultiplier = 2;
		playStage();
		break;
	case 3:
		logger("River is on the table now");
		playStage();
		break;
	case 4:
		logger("Showdown");
		showdown();
		if( game.players.length > 1 ){
			getReadyForNextRound();
			round();
		}
		else{
			declareWinner();
			endGame();
		}
		break;
	default:
		logger("Error terror in code");
	}
}

function correctActivePlayerIndex(){
	if( game.activePlayer >= game.players.length ) game.activePlayer = 0;
	while( !game.players[game.activePlayer].inGame ){
		game.activePlayer++;
		if( game.activePlayer >= game.players.length ) game.activePlayer = 0;
	}
}

function playStage(){
	if( game.playerInGame == 1 ){
		stage = 4;
		round();
	}
	else{
		var cardsToDeal = 1;
		if( stage == 1 ) cardsToDeal = 3;
		for ( var i = 0; i < cardsToDeal; i++ ){
			game.communityCards.push( game.deck[0] );
			writeCommunityCardToHtml( communityCardIndex, game.deck.shift() );
			communityCardIndex++;
		}	
		game.activePlayer = (game.dealer + 1) % game.players.length;
		correctActivePlayerIndex();		
		playerAction();
	}
}

function dealCards( players, deck){
	for( var i = 1; i <= players.length * 2; i++){
		players[ (game.dealer + i) % players.length ].cards.push( deck[0] );
		giveCard( players[i % players.length], deck.shift() );
		//setTimeout( function(){ giveCard( players[i % players.length], deck.shift() ); }, 1000);
	}
}

function burn(){
	game.foldPile.push( game.deck[0] );
	game.deck.shift();
}

function blinds(){
	var numOfPlayers = game.players.length;
	var sbi1 = (game.dealer + 1) %  numOfPlayers;
	var bbi1 = (game.dealer + 2) %  numOfPlayers;
	var sbi2 = (game.dealer) %  numOfPlayers;
	var bbi2 = sbi1;
	if ( numOfPlayers > 2 ){		
		game.players[ sbi1 ].money -= game.smallBlind;
		game.players[ sbi1 ].betSize += game.smallBlind;
		game.players[ bbi1 ].money -= 2 * game.smallBlind;
		game.players[ bbi1 ].betSize += 2 * game.smallBlind;
		
		game.pot += 3 * game.smallBlind;
		game.maxBet += 2 * game.smallBlind;
		game.activePlayer = (game.dealer + 3) % game.players.length;
		
		game.players[ sbi1 ].action = actionSmallBlind;
		game.players[ bbi1 ].action = actionBigBlind;
		
		
	}
	else {
		game.players[ sbi2 ].money -= game.smallBlind;
		game.players[ sbi2 ].betSize += game.smallBlind;
		game.players[ bbi2 ].money -= 2 * game.smallBlind;
		game.players[ bbi2 ].betSize += 2 * game.smallBlind;		
		
		game.pot += 3 * game.smallBlind;
		game.maxBet += 2 * game.smallBlind;
		game.activePlayer = (game.dealer + 1) % game.players.length;
		
		game.players[ sbi2 ].action = actionSmallBlind;
		game.players[ bbi2 ].action = actionBigBlind;
	}
}

function ready(){
	for ( var i = 0; i < game.players.length; i++){
		if (game.players[i].betSize < game.maxBet && game.players[i].inGame){
			return false;
		}
	}
	return allPlayersHaveActed();
}

function playerAction(){
	isActivePlayer( game.players[game.activePlayer] );
	if( game.playersInGame == 1 ){
		stage = 4;
		round();
	}
	else if( ready() ) {
		stage++;
		getReadyForNextStage();
	}
	else if (game.players[game.activePlayer].isHuman){
		if (game.players[game.activePlayer].money > game.maxBet*2){
		$('.playerActionButton').fadeIn(700);
		humanAction();
		}
		else if (game.players[game.activePlayer].money < game.maxBet*2 && game.players[game.activePlayer].money >= game.maxBet){
		$('.call').fadeIn(700);
		$('.fold').fadeIn(700);
		}
		else {logger("Game over for human player")};
	}	
	else {
		$('.playerActionButton').fadeOut(700);
		setTimeout( function(){ botAction(); }, 2000);
	}
}

function getReadyForNextStage(){
	resetHtmlForStage();
	
	for ( var i = 0; i < game.players.length; i++){
		game.players[i].hasActed = false;
		game.players[i].betSize = 0;
		game.players[i].strongestHand = 0;
	}
	game.maxBet = 0;
	timesRaised = 0;
	round();
}

function humanAction(){
	var player = game.players[game.activePlayer];
	$("#check").click(function () {
		check();
		handOverTurn( player );	
	});
	$("#bet").click(function () {
		raise();
		handOverTurn( player );
	});
	$("#fold").click(function () {
		fold();
		handOverTurn( player );		
	});
	$("#call").click(function () {
		call();
		handOverTurn( player );
	});
}

function botAction(){
	var player = game.players[game.activePlayer];
	
	var x = Math.random();
	var moneyToCall = game.maxBet - player.betSize;
	var raiseAmount = game.smallBlind * 2 * betMultiplier;
	
	if( game.maxBet == player.betSize && x < 0.3 ) check();
	else if( x < 0.7 && player.money >= moneyToCall && game.maxBet != 0 ) call();
	else if ( player.money >= moneyToCall + raiseAmount && timesRaised < betLimit){
		raise();
		timesRaised++;
	}
	else if( game.maxBet == player.betSize ) check();
	else fold();//allIn();
	handOverTurn( player );
	
}

function handOverTurn( player ){
	writePlayerDataToHtml( player );
	setTimeout( function(){ removeActivePlayer( player ); }, 200);
	game.activePlayer++;
	correctActivePlayerIndex();
	playerAction();
}

function check(){
	logger(game.players[game.activePlayer].name + " check");
	game.players[game.activePlayer].hasActed = true;
	game.players[game.activePlayer].action = actionCheck;
}

function call(){
	logger(game.players[game.activePlayer].name + " call " + "$" + (game.maxBet - game.players[game.activePlayer].betSize));
	bet( game.maxBet - game.players[game.activePlayer].betSize );
	game.players[game.activePlayer].action = actionCall;
}

function raise(){
	logger(game.players[game.activePlayer].name + " raise " + "$" +(game.maxBet - game.players[game.activePlayer].betSize + game.smallBlind * 2 * betMultiplier));
	bet( game.maxBet - game.players[game.activePlayer].betSize + game.smallBlind * 2 * betMultiplier );
	game.players[game.activePlayer].action = actionRaise;
}

function fold(){
	logger(game.players[game.activePlayer].name + " fold");
	var player = game.players[game.activePlayer];
	game.foldPile.push(player.cards);
	player.cards.splice(0, 2);
	player.inGame = false;
	player.action = actionFold;
	player.hasActed = true;
	game.playersInGame--;
	
	foldPlayerCards( player );
}

function bet( amount ){
	var player = game.players[game.activePlayer];
	player.money -= amount;
	player.betSize += amount;
	if (game.maxBet < player.betSize) game.maxBet = player.betSize;
	game.pot += amount;
	writePotAmountToHtml(game.pot);
	logger("Pot is now $" + game.pot);
	player.hasActed = true;
}

function allPlayersHaveActed(){
	for ( var i = 0; i < game.players.length; i++ ){
		if( !game.players[i].hasActed && game.players[i].inGame ) return false;
	}
	return true;
}

function showdown(){
	if( game.playersInGame == 1 ){
		for( var i = 0; i < game.players.length; i++){
			if( game.players[i].inGame ) {
				game.players[i].money += game.pot;
				break;
			}
		}
	}
	else{
		
		for( var i=0; i<game.players.length; i++ ) {
			if ( game.players[i].inGame ) {
		setTimeout( function (){ showPlayerCards(game.players[i]); }, 3000);
				//showPlayerCards( game.players[i] );
			}
		}
		var bestHand = new Array();
		var bestHandStrength = 0;
		var winners = new Array();
		for( var i = 0; i < game.players.length; i++ ){
			player = game.players[i];
			if( player.inGame){
				bestHand = findBestHand( player );
			}
		}
		for( var i = 0; i < game.players.length; i++ ){
			if( game.players[i].strongestHand > bestHandStrength && game.players[i].inGame){
				bestHandStrength = game.players[i].strongestHand;
				winners = new Array();
				winners.push(game.players[i]);
			}
			else if( game.players[i].strongestHand == bestHandStrength && game.players[i].inGame){
				winners.push( game.players[i] );
			}
		}
		for( var i = 0; i < winners.length; i++ ){
			winners[i].money += game.pot / winners.length;
			logger("Winner is: " + winners[i].name + ", winnings $" + winners[i].money);
		}
		
	}
	
}

function getReadyForNextRound(){
	stage = 0;
	removeDealer( game.players[game.dealer] );
	game.dealer++;
	game.pot = 0;
	eliminateBrokePlayers();
	if( game.dealer >= game.players.length ){
		game.dealer = 0;
		//if( game.smallBlind < 16 ) 
			game.smallBlind *= 2;
	}
	communityCardIndex = 0;
	for( var i = 0; i < game.players.length; i++ ){
		game.players[i].inGame = true;
		game.players[i].cards = new Array();
	}
	logger("Next round starts");
	game.communityCards = new Array();
	game.foldPile = new Array;
	
	resetHtmlForRound();
	clearPlayerHands();
	getReadyForNextStage();
}

function eliminateBrokePlayers(){
	var playersInGame = new Array();
	for( var i = 0; i < game.players.length; i++ ){
		if( game.players[i].money >= game.smallBlind * 2 ){
			playersInGame.push( game.players[i] );
		}
		else{
			hidePlayer( game.players[i] ); 
			if( i < game.dealer ) gameStatus.dealer--;
		}
	}
	game.players = playersInGame;
	
	logger("Players left in game after round: " + game.players.length);
}

function declareWinner(){
	if(game.players.length == 1) logger(game.players[0].name + " won the game");
	else alert("error");
	winnerDeclared = true;
}

function findBestHand( player ){
	var cards = game.communityCards.concat( player.cards );
	var bestHand = new Array();
	for( var i = 0; i < cards.length - 1; i++){
		for( var j = i + 1; j < cards.length; j++){
			sampleHand = viewHand(cards, i, j);
			sampleHandStrength = evalHand(sampleHand);
			if( player.strongestHand < sampleHandStrength ){
				player.strongestHand = sampleHandStrength;
				bestHand = sampleHand;
			}
		}
	}
	return bestHand;
}

function viewHand( cards, i, j ){
	var hand = new Array();
	for( var k = 0; k < cards.length; k++) if( k != i && k != j ) hand.push(cards[k]);
	return hand;
}

function evalHand( cards ) {
	if (hasRoyalFlush( cards )) return 1000000;
	else if (hasStraightFlush( cards )) return 900000 + highCard(cards);
	else if (hasFourOfAKind( cards )) return 800000 + addedValue(cards, "four");
	else if (hasFullHouse( cards )) return 700000 + addedValue(cards, "house");
	else if (hasFlush( cards )) return 600000 + highCard(cards);
	else if (hasStraight( cards )) return 500000 + highCard(cards);	
	else if (hasThreeOfAKind( cards )) return 400000 + addedValue(cards, "three");
	else if (hasTwoPairs( cards )) return 300000 + addedValue(cards, "2pair");
	else if (hasPair( cards )) return 200000 + addedValue(cards, "pair");
	else return highCard( cards );	
}

function hasRoyalFlush( cards ){	
	if (hasCard( cards, "A" ) && hasCard( cards, "K" ) && hasStraightFlush( cards )) return true;
	else return false;
}

function hasStraightFlush( cards ){
	if ( hasStraight( cards ) && hasFlush( cards ) ) return true;
	else return false;
}

function hasFourOfAKind( cards ){
	var sortedHandHist = cards.sort( sortNumber );
	if (sortedHandHist[0] == 4 ) return true;
	else return false;
}

function hasFullHouse( cards ){
	var sortedHandHist = makeHist( cards ).sort( sortNumber );
	if (sortedHandHist[0] == 3 && sortedHandHist[1] == 2) return true;
	else return false;
}

function hasFlush( cards ){
	var hasFlush = true;
	var suit = cards[0].suit;
	for ( var i = 1; i < cards.length; i++ ){
		if (cards[i].suit != suit){
			hasFlush = false;
			break;
		}
	}
	return hasFlush;
}

function hasStraight( cards ){
	var hasStraight = true;
	var handHist = makeHist( cards );
	for(var i = 0; i < handHist.length; i++){
		if( handHist[i] != 1){
			hasStraight = false;
			break;
		}
	}	
	return hasStraight;
}

function hasThreeOfAKind( cards ){
	var sortedHandHist = makeHist( cards ).sort( sortNumber );
	if (sortedHandHist[0] == 3 && sortedHandHist[1] < 2) return true;
	else return false;
}

function hasTwoPairs( cards ){
	var sortedHandHist = makeHist( cards ).sort( sortNumber );
	if (sortedHandHist[0] == 2 && sortedHandHist[1] == 2 && sortedHandHist[2] < 2 ) return true;
	else return false;
}

function hasPair( cards ){		
	var sortedHandHist = makeHist( cards ).sort( sortNumber );
	if (sortedHandHist[0] == 2 && sortedHandHist[1] < 2) return true;
	else return false;
}

function highCard( cards ){
	var maxValue = cardValues[0];
	var handHist = makeHist( cards );
	if ( handHist[0] > 0 ) return maxValue;
	else {
		for (i = cards.length - 1; i > 0; i--){
			maxValue -= 1;
			if (handHist[i] > 0) break;
		}
	}
	return maxValue;
}

function hasCard( cards, number ){
	var playerHasCard = false;
	for ( var i = 0; i < cards.length; i++ ){
		if (cards[i].number == number){
			playerHasCard = true;
			break;
		}
	}
	return hasCard;
}

function addedValue( cards, hand ){
	var handHist = makeHist( cards );	
	if(hand == "house"){
		addedHandValue = 0;
		for(i = 0; i < handHist.length; i++){
			if(handHist[i] == 3) addedHandValue += 100 * cardValues[0];
			if(handHist[i] == 2) addedHandValue += cardValues[0];
		}
		return addedHandValue;
	}
	else if( hand == "four" ) return handValue( handHist, 10, 4 ) + evalKicker( handHist, 1 );	
	else if(hand == "three")return handValue( handHist, 100, 3 ) + evalKicker( handHist, 10 );
	else if( hand == "2pair" ) return handValue( handHist, 100, 2 ) + evalKicker( handHist, 1 );
	else if(hand == "pair") return handValue( handHist, 1000, 2 ) + evalKicker( handHist, 100 );		
	else return 0;
}

function handValue( handHist, multiplier, pattern){
	var value = 0;
	var multiplier = multiplier;
	if (handHist[0] == pattern){
		value += cardValues[0] * multiplier;
		multiplier /= 10;
	}
	for( var i = handHist.length - 1; i > 0; i-- ){
		if( handHist[i] == pattern ){
			if( multiplier < 1 ) break;
			value += cardValues[i] * multiplier;
			multiplier /= 10;
		}
	}
	return value;
}

function evalKicker( handHist, multiplier ) {
	var kickerValue = 0;
	var multiplier = multiplier;
	var kickers = handHist;
	for(i = 0; i < kickers.length; i++){
		if( kickers[i] != 1 ) kickers[i] = 0;
	}
	if(kickers[0] == 1){
		kickerValue += cardValues[0] * multiplier;
		multiplier /= 10;
	}
	for(i = kickers.length - 1; i > 0; i--){
		if( multiplier < 1 ) break;
		if(kickers[i] == 1){
			kickerValue += cardValues[i] * multiplier;
			multiplier /= 10;
		}
	}		
	return kickerValue;
}

function makeHist( cards ){
	var hist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
	for( var i = 0; i < cards.length; i++ ){
		if ( cards[i].number == "A" ) hist[0]++;
		if ( cards[i].number == "2" ) hist[1]++;
		if ( cards[i].number == "3" ) hist[2]++;
		if ( cards[i].number == "4" ) hist[3]++;
		if ( cards[i].number == "5" ) hist[4]++;
		if ( cards[i].number == "6" ) hist[5]++;
		if ( cards[i].number == "7" ) hist[6]++;
		if ( cards[i].number == "8" ) hist[7]++;
		if ( cards[i].number == "9" ) hist[8]++;
		if ( cards[i].number == "10" ) hist[9]++;
		if ( cards[i].number == "J" ) hist[10]++;
		if ( cards[i].number == "Q" ) hist[11]++;
		if ( cards[i].number == "K" ) hist[12]++;
	}
	return hist;
}

function sortNumber(a, b) {
	return b - a;
}

		// ** FUN ** //


function giveCard( player, card ) {
	$('#bot' + player.id + ' .card' + player.cards.length ).fadeIn();
}
function writePlayerDataToHtml ( player ) {
	$('#bot' +player.id+ ' .name').html( player.name );
	$('#bot' +player.id+ ' .action').html( player.action );
	if ( player.betSize != 0 ) {
		$('#bot' +player.id+ ' .betSize').html( 'Bet $' + player.betSize );
	} else {
		$('#bot' +player.id+ ' .betSize').html( '' );
	}	
	$('#bot' +player.id+ ' .amount').html( '$' + player.money );
}

function hidePlayer ( player ) {
	$('#bot' +player.id ).css({'visibility': 'hidden'});
}

function showPlayerCards( player ) {
	for( var i = 1; i < 3; i++){
		$('#bot' + player.id + ' .card' + i + ' .top').html(player.cards[i - 1].number);
		$('#bot' + player.id + ' .card' + i + ' .bottom').html(player.cards[i - 1].number);
		$('#bot' + player.id + ' .card' + i + ' .smallSuit').html(''+ getSuit(player.cards[i - 1].suit)+ '');
		$('#bot' + player.id + ' .card' + i ).addClass(''+ getCardColor(player.cards[i - 1].suit)+'');
		$('#bot' + player.id + ' .card' + i ).removeClass('backSide');
	}
}

function isDealer ( player ) {
	$('#bot' +player.id+ ' .playerInfo').css({'background-color': '#f3b336'});
}

function removeDealer ( player ) {
	$('#bot' +player.id+ ' .playerInfo').css({'background-color': '#D3D3D3'});
}

function writePotAmountToHtml ( amount ) {
	$('.pot').html( 'Pot: $'+amount );
}

function foldPlayerCards( player ) {
	$('#bot' + player.id + ' .card1').fadeOut(700);
	$('#bot' + player.id + ' .card2').fadeOut(700);
}

function isActivePlayer( player ) {
	$('#bot' + player.id).addClass('activePlayer');
}

function removeActivePlayer( player ) {
	$('#bot' + player.id).removeClass('activePlayer');
}

function writeCommunityCardToHtml( cardPos, card ) {
	switch ( card.suit ) {
	case 'S':
		$('#community' + cardPos + '').addClass('black');
		$('#community' + cardPos + ' .suit').html('&spades;');
		break;
	case 'H':
		$('#community' + cardPos + '').addClass('red');
		$('#community' + cardPos + ' .suit').html('&hearts;');
		break;
	case 'D':
		$('#community' + cardPos + '').addClass('red');
		$('#community' + cardPos + ' .suit').html('&diams;');
		break;
	case 'C':
		$('#community' + cardPos + '').addClass('black');
		$('#community' + cardPos + ' .suit' ).html('&clubs;');
		break;	
	}
	
	$('#community' + cardPos + ' .top').html(card.number);
	$('#community' + cardPos + ' .bottom' ).html(card.number);
	$('#community' + cardPos + '').fadeIn(700);
}

function clearTable() {
	$('#community0').fadeOut(700).removeClass('red black');
	$('#community1').fadeOut(700).removeClass('red black');
	$('#community2').fadeOut(700).removeClass('red black');
	$('#community3').fadeOut(700).removeClass('red black');
	$('#community4').fadeOut(700).removeClass('red black');
	writePotAmountToHtml( 0 );
}

function clearPlayerHands(){
	for( var i = 0; i < game.players.length; i++){
		for( var j = 1; j < 3; j++){
			$('#bot' + game.players[i].id + ' .card' +j+ ' .top').empty();
			$('#bot' + game.players[i].id + ' .card' +j+ ' .bottom').empty();
			$('#bot' + game.players[i].id + ' .card' +j+ ' .smallSuit').empty();
			$('#bot' + game.players[i].id + ' .card' + j).removeClass('red black');
			$('#bot' + game.players[i].id + ' .card' + j).addClass('backSide');
			$('#bot' + game.players[i].id + ' .card' + j).addClass('backSide');
		}
	}
}

function clearPlayerData(){
	for( var i = 0; i < game.players.length; i++){
		$('#bot' + game.players[i].id + ' .action').html( '' );
		$('#bot' + game.players[i].id + ' .betSize').html( '' );
	}
}

function resetActivePlayerMarker(){
	for( var i = 0; i < game.players.length; i++){
		$('#bot' + game.players[i].id).removeClass('activePlayer');
	}
}

function resetHtmlForStage(){
	resetActivePlayerMarker();
	clearPlayerData();
}

function resetHtmlForRound(){
	clearPlayerHands();
	clearTable();
	resetHtmlForStage();
}


function getSuit( suit ) {
	switch ( suit ) {
	case 'S':
		return '&spades;';
		break;
	case 'H':
		return '&hearts;';
		break;
	case 'D':
		return '&diams;';
		break;
	case 'C':
		return '&clubs;';
		break;	
	}
}

function getCardColor( suit ) {
	switch ( suit ) {
	case 'S':
		return 'black';
		break;
	case 'H':
		return 'red';
		break;
	case 'D':
		return 'red';
		break;
	case 'C':
		return 'black';
		break;	
	}
}

function logger( text ) {
	if ( viewLog == true ) {
		var show = $('#logArea').html() + text + '<br/>'; 
		$('#logArea').html(show);
		$('#logArea').animate({ scrollTop: 60000 }, 'slow');
		return false;
	} 
} 